package logic

import (
	"context"
	"pa/parpc/parpc"

	"pa/api/internal/svc"
	"pa/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodCarAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGoodCarAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodCarAddLogic {
	return &GoodCarAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GoodCarAddLogic) GoodCarAdd(req *types.GoodCarAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	add, err := l.svcCtx.PaRpc.GoodCarAdd(l.ctx, &parpc.GoodCarAddRequest{
		GoodId: int64(req.GoodId),
		Title:  req.Title,
		Price:  float32(req.Price),
		Num:    int64(req.Num),
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    nil,
			Code:    500,
		}, nil
	}

	return &types.Response{
		Message: "购物车商品添加成功",
		Data:    add,
		Code:    200,
	}, nil
}
